﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Sole
{
    public abstract class Entity : DrawableGameComponent
    {
        public Vector2 position;
        public Vector2 velocity = Vector2.Zero; //enbart riktningsvector
        public Vector2 origin; //origo, pivot point 
        public Vector2 scale = new Vector2(1.0f, 1.0f);
        public float rotation = 0.0f;
        public Color color = Color.White; //for ex. effects, otherwise shaders/sprite sheets

        public float speed = 0.5f;
        public bool killMe = false;
        public Rectangle screenBoundaries;

        protected Texture2D texture;
        protected SpriteBatch spritebatch;

        public Rectangle ScreenBoundaries
        {
            get { return screenBoundaries; }
            set { screenBoundaries = value; }
        }

        public Rectangle CollisionBox
        {
            get
            {
                int x = (int)(position.X - origin.X);
                int y = (int)(position.Y - origin.Y);
                return new Rectangle(x, y, texture.Width, texture.Height);
            }
        }

        public Texture2D Texture
        {
            get { return texture; }
        }

        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }

        public Vector2 Velocity
        {
            get { return velocity; }
            set { velocity = value; }
        }

        public bool KillMe
        {
            get { return killMe; }
            set { killMe = value; }
        }

        public Entity(SpriteBatch spriteBatch, Game game)
            : base(game)
        {
            this.spritebatch = spriteBatch;
        }

        public override void Draw(GameTime gameTime)
        {
            spritebatch.Draw(texture, position, null, color, rotation, origin, scale, SpriteEffects.None, 0.0f);
        }

        public abstract void OnCollision();
    }
}
